package com.csdj.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.csdj.pojo.IvArchive;
import com.csdj.pojo.IvInvoice;
import com.csdj.service.IvInvoiceService;
import com.csdj.mapper.IvInvoiceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author 叶涵
 * @description 针对表【iv_invoice】的数据库操作Service实现
 * @createDate 2023-08-24 15:13:39
 */
@Service
public class IvInvoiceServiceImpl extends ServiceImpl<IvInvoiceMapper, IvInvoice>
        implements IvInvoiceService {

    @Autowired
    private IvInvoiceMapper invoiceMapper;

    @Override
    public int getCount(Integer startNo, Integer endNo) {
        LambdaQueryWrapper<IvInvoice> qw = new LambdaQueryWrapper<>();
        qw.between(IvInvoice::getInvoiceNo, startNo, endNo);
        Long aLong = getBaseMapper().selectCount(qw);
        int count = aLong.intValue();
        return count;
    }

    @Override
    public boolean Update(int startNo, int endNo,int OutId,int empID) {
        LambdaUpdateWrapper<IvInvoice> lw=new LambdaUpdateWrapper<>();

        lw.between(IvInvoice::getInvoiceNo,startNo,endNo).set(IvInvoice::getOutID,OutId).set(IvInvoice::getEmpID,empID);
        boolean update = update(lw);
        return update;
    }

    @Override
    public int getCountByStartNoAndEndNoAndUserd(int startNo, int endNo) {
        LambdaQueryWrapper<IvInvoice> qw = new LambdaQueryWrapper<>();
        qw.between(IvInvoice::getInvoiceNo, startNo, endNo).and(LambdaQueryWrapper ->LambdaQueryWrapper.eq(IvInvoice::getUsed,0).eq(IvInvoice::getInvalid,0));
        Long aLong = getBaseMapper().selectCount(qw);
        int count = aLong.intValue();
        return count;
    }

    @Override
    public boolean UpdateArchive(IvArchive ivArchive) {
        LambdaUpdateWrapper<IvInvoice> lq=new LambdaUpdateWrapper<>();
        lq.between(IvInvoice::getInvoiceNo,Integer.parseInt(ivArchive.getStartNo()),Integer.parseInt(ivArchive.getEndNo())).set(IvInvoice::getArchiveID,ivArchive.getID()).
                set(IvInvoice::getArchived,1).set(IvInvoice::getArchiveDate,ivArchive.getArchiveDate());
        boolean update = update(lq);
        return update;
    }

    @Override
    public Map invoiceReportUse(Map<String, String> map) {
        return invoiceMapper.invoiceReportUse(map);
    }

    @Override
    public Page<Map> invoiceReportUse2(Page<Map> page,Map<String, String> map) {
        return invoiceMapper.invoiceReportUse2(page,map);
    }

    @Override
    public Map invoiceReportMoneySum1(Map<String, String> map) {
        return invoiceMapper.invoiceReportMoneySum1(map);
    }

    @Override
    public List<Map> invoiceReportMoneySum2(Map<String, String> map) {
        return invoiceMapper.invoiceReportMoneySum2(map);
    }

    @Override
    public Page<Map> invoiceReportMoneyDetail(Page<Map> page, Map map) {
        return invoiceMapper.invoiceReportMoneyDetail(page,map);
    }

}




